package Interfaces;

import SistemaCocheras.Tickets;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author Tinacho
 */
public class salidaSatisfactoria extends javax.swing.JDialog {

    
    Connection conexion;
    ResultSet estaEnCochera;
    String dominioVehiculo = "";
    String tiempoEstadia = "";
    String fecha = "";
    String hora = "";
    Double[] tarifa;
    Double monto;    

    /**
     * Constructor NO vacio
     * @param parent
     * @param modal 
     */
    public salidaSatisfactoria(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        centrarJDialog();
    }
    
    
    /**
     * Funcion encargada de setear los valores correctamente
     * @param con
     * @param esta
     * @param f
     * @param h
     * @param t
     * @param m 
     */    
    public void obtenerValores(Connection con, String dominio, ResultSet esta, String f, String h, Double[] t, Double m, String tpoEstadia){
        this.jLabel_Dominio.setText(dominio);
        this.jLabel_Monto.setText(Double.toString(m));
        this.jLabel_TpoEstadia.setText(tpoEstadia);
        this.dominioVehiculo = dominio;
        this.conexion = con;
        this.estaEnCochera = esta;
        this.fecha = f;
        this.hora = h;
        this.tarifa = t;
        this.monto = m;
        this.tiempoEstadia = tpoEstadia;
    }// Fin obtenerValores     

    
    /**
     * Funcion encargada de centrar el dialogo en la pantalla
     */
    private void centrarJDialog(){
        Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frame = this.getSize();
        this.setLocation((pantalla.width-frame.width)/2, (pantalla.height-frame.height)/2);
    }// Fin centrarJDialog
    
    

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel_Introduccion = new javax.swing.JLabel();
        jLabel_Dominio = new javax.swing.JLabel();
        jLabel_$ = new javax.swing.JLabel();
        jLabel_Monto = new javax.swing.JLabel();
        botonAceptar = new javax.swing.JButton();
        jLabel_TpoEstadiaT = new javax.swing.JLabel();
        jLabel_TpoEstadia = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Salida Satisfactoria");

        jLabel_Introduccion.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel_Introduccion.setText("Monto del vehículo con dominio");

        jLabel_Dominio.setFont(new java.awt.Font("Tahoma", 1, 16));

        jLabel_$.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel_$.setText(" : $");

        jLabel_Monto.setFont(new java.awt.Font("Tahoma", 1, 16));

        botonAceptar.setText("Aceptar");
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        jLabel_TpoEstadiaT.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel_TpoEstadiaT.setText("Tiempo de estadía :");

        jLabel_TpoEstadia.setFont(new java.awt.Font("Tahoma", 1, 16));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(botonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(165, 165, 165))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel_TpoEstadiaT, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel_TpoEstadia, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel_Introduccion, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel_Dominio, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel_$)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel_Monto, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_TpoEstadiaT)
                    .addComponent(jLabel_TpoEstadia, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_$)
                    .addComponent(jLabel_Monto, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel_Introduccion)
                    .addComponent(jLabel_Dominio, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(botonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    /**
     * 
     * @param evt 
     */
    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        try {
            Tickets ticket = new Tickets(this.conexion);
            ticket.imprimirTicketEgreso(this.estaEnCochera, this.dominioVehiculo, this.fecha, this.hora, this.monto);
            this.dispose();
        } 
        catch (IOException ex ) {
            JOptionPane.showMessageDialog(null, " Se produjo un error al intentar dar de baja el vehículo con dominio: "+ this.dominioVehiculo, "Salida Fallida", JOptionPane.ERROR_MESSAGE);
        }
        catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, " Se produjo un error al intentar dar de baja el vehículo con dominio: "+ this.dominioVehiculo, "Salida Fallida", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_botonAceptarActionPerformed


    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(salidaSatisfactoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(salidaSatisfactoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(salidaSatisfactoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(salidaSatisfactoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                salidaSatisfactoria dialog = new salidaSatisfactoria(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JLabel jLabel_$;
    private javax.swing.JLabel jLabel_Dominio;
    private javax.swing.JLabel jLabel_Introduccion;
    private javax.swing.JLabel jLabel_Monto;
    private javax.swing.JLabel jLabel_TpoEstadia;
    private javax.swing.JLabel jLabel_TpoEstadiaT;
    // End of variables declaration//GEN-END:variables

}// Fin clase CartelSalida_Satisf
